<?php
/**
 * Created by PhpStorm.
 * User: Qiangguo
 * Date: 14-9-9
 * Time: 下午10:03
 */
namespace User\Controller;
use Think\Controller;
class LoginController extends Controller {
    public function index(){
        $this->display('Login:login');
    }
    public function hello(){
        $data['name'] = 'hahahahahahah';
        $data['email'] = 'thinkphp@qq.com';
        $this->assign('data',$data);

        $this->display('Login:login');
        /*        $this->display(T('Login/login'));*/
    }
    public function loginRedirect(){
        $this->display('Login:login');
        /*        $this->display(T('Login/login'));*/
    }

    public function read($id){
        echo 'id='.$id;
    }
    public function archive($year='2014',$month='01'){
        echo 'year='.$year.'&month='.$month;
    }
    public function redirectPhp(){
        echo 'redirect,thinkphp!';
        redirect(U('User/Login/hello'), 1, '用户不存在...');
    }
    public function logout(){
        unset($_SESSION['user']);
        $this->loginRedirect();
    }


    public function loginAction(){
        $params = $_POST;
        if(!$params){
            return;
        }
        $Dao = M("User");
        // 查询数据
        $list=$Dao->where("userid= '%s'",$params['user_id'])->select();

        if(count($list)==0){
            $this->redirectPhp();
        }elseif(count($list)==1){
            if($list[0]["pwd"]!=$params["pwd"]){
                redirect(U('User/Login/hello'), 1, '密码错误...');
            }
            session('user',$list[0]);  //设置session
            // 输出模板
            redirect(U('/User/Activity/myActivity'));
        }
        // 模板变量赋值
        // 输出模板
        /* $this->display();*/
    }
}